
/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"9DBDB00D-239E-4AA2-8D96-E633F8117C53"}
 */
function nuevo(event) {
	if (hoteles_to_hoteles_social.getSize() < 5)
		hoteles_to_hoteles_social.newRecord()
	else
		globals.DIALOGS.showWarningDialog('Aviso','Ha llegado al limite de 5 redes sociales','OK')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"57F373EE-0138-4D64-B8DF-F64A94D793ED"}
 */
function eliminar(event) {
	hoteles_to_hoteles_social.deleteRecord()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"3BA6411A-D10D-4E3D-AE92-79EEA85F6F48"}
 */
function cargarFotoPpal(event) {
	plugins.file.showFileOpenDialog(null, null, false, new Array("Images", "jpg", "gif", "png", "*"), fotoHome, 'Seleccione la foto')
}

/**
 * @param {Array<plugins.file.JSFile>} foto
 * 
 * @properties={typeid:24,uuid:"41F9C137-4C5A-49F8-9353-D86B69D494EE"}
 */
function fotoHome(foto)
{
	var $img = plugins.images.getImage(foto[0].getBytes());
	hoteles_to_hoteles_fotos.foto_home = $img
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"06D20320-5A91-4891-AAC5-236AD0BD9174"}
 */
function cargarLogo(event) {
	plugins.file.showFileOpenDialog(null, null, false, new Array("Images", "jpg", "gif", "png", "*"), grabarLogo, 'Seleccione el logo')
}

/**
 * @param {Array<plugins.file.JSFile>} foto
 * 
 * @properties={typeid:24,uuid:"DCB2C511-12AD-4647-BA22-EC73FB906CF3"}
 */
function grabarLogo(foto)
{
	var $img = plugins.images.getImage(foto[0].getBytes());
	hoteles_to_hoteles_fotos.logo = $img
}

/**
 * @properties={typeid:24,uuid:"55552647-2CEC-4DEC-B1DB-5F15BD7143DB"}
 */
function guardar() {
	if (!nombre_fantasia || !pais_id || !div_territorial_id || !direccion || !telefonos || !direccion_web || 
	!direccion_mail || !categoria_id || !check_in || !check_out || !dias_tope)
	{
		globals.DIALOGS.showWarningDialog('Aviso','Por favor, ingrese todos los campos obligatorios','OK')
		return false
	}
	if (valida() == false)
	{
		globals.DIALOGS.showErrorDialog('Aviso','El nombre ya existe. Por favor, ingrese otro','OK')
		return false
	}
	if (databaseManager.saveData() == true)
	{
		globals.llenarVlHoteles()
		globals.DIALOGS.showInfoDialog('Aviso','Datos modificados con éxito','OK')
		return true
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrio un error al grabar. Inténtelo nuevamente', 'OK')
		return false
	}
}

/**
 * @properties={typeid:24,uuid:"1E863384-85C4-46A8-B16E-437256275506"}
 */
function valida()
{
	var $sql = 'SELECT hotel_id FROM hoteles WHERE upper(nombre_fantasia) = upper(?)AND cadena_id = ? AND hotel_id != ?'
	var $args = [nombre_fantasia, globals.gCadena, hotel_id]
	var $ds = databaseManager.getDataSetByQuery('hoteleria',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
		return true
	return false
}

/**
 * @properties={typeid:24,uuid:"97E39C8C-BD29-49A3-B657-E9A72C04D81D"}
 */
function cancelar() {
	databaseManager.revertEditedRecords()
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"6DCBB2C0-D3BA-4060-9540-B05856F4B661"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	return true
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4D2291B7-ED41-4C15-939F-2A9A7103706B"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}
